<template>
    <div id="seachDialog">
      <a-modal
      title="快速筛选"
      width="550px"
      :visible="searchData.show"
      @cancel="handleClose">
        <el-row style="padding:30px 70px 50px 20px;overflow-y:auto;height:580px;overflow-x:hidden;">
            <el-form :model="searchParames" ref="searchParames" label-width="120px">
                <el-form-item label="公司名称:">
                    <el-input clearable size="small" v-model="searchParames.customerName" placeholder="请输入"></el-input>
                </el-form-item>
                <el-form-item label="简称:">
                    <el-input clearable size="small" v-model="searchParames.shortName" placeholder="请输入"></el-input>
                </el-form-item>
                <el-form-item label="曾用名:">
                    <el-input clearable size="small" v-model="searchParames.previousName" placeholder="请输入"></el-input>
                </el-form-item>
                <el-form-item label="社会信用代码:">
                    <el-input clearable size="small" v-model="searchParames.creditCode" placeholder="请输入"></el-input>
                </el-form-item>
                <el-form-item label="企业电话:">
                    <el-input clearable size="small" v-model="searchParames.businessPhone" placeholder="请输入"></el-input>
                </el-form-item>
                <el-form-item label="企业邮箱:">
                    <el-input clearable size="small" v-model="searchParames.businessEmail" placeholder="请输入"></el-input>
                </el-form-item>
                <el-form-item label="客户等级:">
                    <el-select clearable style="width:100%" size="small" v-model="searchParames.customerLevel">
                        <el-option v-for="(item,index) in customerLevelData" :key="index" :label="item.desc" :value="item.name"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="废业状态:">
                    <el-select clearable style="width:100%" size="small" v-model="searchParames.wasteIndustry">
                        <el-option label="是" :value="true"></el-option>
                        <el-option label="否" :value="false"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="黑户状态:">
                    <el-select clearable style="width:100%" size="small" v-model="searchParames.blacklisted">
                        <el-option label="是" :value="true"></el-option>
                        <el-option label="否" :value="false"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="联系地址:">
                    <el-input clearable size="small" v-model="searchParames.address" placeholder="请输入"></el-input>
                </el-form-item>
                <el-form-item label="备注:">
                    <el-input clearable size="small" v-model="searchParames.remark" placeholder="请输入"></el-input>
                </el-form-item>
                <el-form-item label="客户来源:">
                    <shangJi clearable v-model="searchParames.customerSourceId" @checkValue="checkValue" :typeid="searchParames.customerSourceType" :id="searchParames.customerSourceId" :type="'new'"></shangJi>
                </el-form-item>
                <el-form-item label="客户负责人:">
                    <el-input clearable size="small" v-model="searchParames.director" placeholder="请输入"></el-input>
                    <!-- <userTree clearable v-model="searchParames.director" :currentValue="searchParames.director"></userTree> -->
                </el-form-item>
            </el-form>
        </el-row>
        <span slot="footer" class="dialog-footer">
            <el-button size="small" @click="handleReset">重置</el-button>
            <el-button size="small" type="primary" @click="handleSend">查询</el-button>
        </span>
      </a-modal>
    </div>
</template>

<script>
export default {
    props: ['searchData'],
    data() {
        return {
          searchParames: {
            customerName: '',//客户名称
            shortName: '',//简称
            previousName: '',//曾用名
            creditCode: '',//社会信用代码
            businessPhone: '',//企业电话
            businessEmail: '',//企业邮箱
            customerLevel: '',//POTENTIAL_CUSTOMER
            address: '',//联系地址
            remark: '',//备注
            wasteIndustry: '', //废业状态
            blacklisted: '',
            customerSourceType: '',//CUSTOMER
            customerSourceId: '',//客户来源ID
            director: '',//负责人
          },
          customerLevelData: [], //客户等级
        };
    },
    methods: {
        handleSend () {
            let searchDate = []
            for(var key in this.searchParames){
                if (this.searchParames[key]) {
                    if (key == 'customerLevel' || key == 'customerSourceType') {
                        searchDate.push({
                            key: key,
                            value: this.searchParames[key],
                            type: 'enumeration'
                        })
                    } else if ( key == 'wasteIndustry' || key == 'blacklisted') {
                        searchDate.push({
                            key: key,
                            value: this.searchParames[key],
                            type: 'bool'
                        })
                    } else {
                        searchDate.push({
                            key: key,
                            value: this.searchParames[key],
                            type: 'string'
                        })
                    }
                }
            }
            this.$emit('checkSearch',searchDate)
            this.handleClose()
        },
        checkValue (value) { //来源获取信息
            this.searchParames.customerSourceType = value
        },
        handleClose () {
            this.searchData.show = false
        },
        handleReset () {
            this.searchParames.contacts = '' //联系人
            this.searchParames.customerName = ''//客户名称
            this.searchParames.shortName = ''//简称
            this.searchParames.previousName = ''//曾用名
            this.searchParames.creditCode = ''//社会信用代码
            this.searchParames.businessPhone = ''//企业电话
            this.searchParames.businessEmail = ''//企业邮箱
            this.searchParames.customerLevel = ''//POTENTIAL_CUSTOMER
            this.searchParames.address = ''//联系地址
            this.searchParames.remark = ''//备注
            this.searchParames.wasteIndustry = ''
            this.searchParames.blacklisted = ''
            this.searchParames.customerSourceType = ''//CUSTOMER
            this.searchParames.customerSourceId = ''//客户来源ID
            this.searchParames.director = ''//负责人
            this.$emit('resetSearch')
            this.$refs.searchParames.resetFields()
        }
    },
    computed: {
      changeDialog () {
        return this.searchData.show
      }
    }, 
    watch: {
      changeDialog: {
        handler (curVal, oldVal) {
          if (curVal) {
            this.$utils.getEnumberation('postCustomerLevel','customerLevelData',this) //客户等级
            this.searchParames.customerName = this.searchData.customerName
          } else {
          }
        }
      }
    },
};
</script>

<style>
#seachDialog .el-dialog{
    padding-bottom: 0; 
    overflow-x: hidden;
}
#seachDialog .el-dialog__footer{
    border-top: #f4f4f4 solid 1px;
}
.ant-modal-body{
    padding: 0
}
</style>
